import Qt 4.7
import Qt.labs.particles 1.0
import "Control"

Item {
    id: waterBubble
    property real bubbleColor: 1

    //This is a desktop-sized example
    width: 800; height: 480

    MouseArea {
        width: 800
        height: 448
        anchors.rightMargin: 0
        anchors.bottomMargin: 0
        anchors.fill: parent
        onClicked: {
            try {
                if (bubbleColor == 1){
                Qt.createQmlObject("import Qt 4.7\nImage {\n    id: whitebubble\n    x:" + mouseX + "-40  \n    y: " + mouseY + "-40 \n    source: 'images/Bluebubble.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 5000\n    }\n    Component.onCompleted: whitebubble.destroy(2000); \n} ", waterBubble, 'CustomObject');
                } else if (bubbleColor == 2)
                    {
                    Qt.createQmlObject("import Qt 4.7\nImage {\n    id: pinkbubble\n    x:" + mouseX + "-40  \n    y: " + mouseY + "-40 \n    source: 'images/bubble.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 5000\n    }\n    Component.onCompleted: pinkbubble.destroy(2000); \n} ", waterBubble, 'CustomObject');
                }  else if (bubbleColor == 4)
                    {
                Qt.createQmlObject("import Qt 4.7\nImage {\n    id: bubble\n    x:" + mouseX + "-40  \n    y: " + mouseY + "-40 \n    source: 'images/Greenbubble.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 5000\n    }\n    Component.onCompleted: bubble.destroy(2000); \n} ", waterBubble, 'CustomObject');
                }


            } catch(err) {
                dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message);
            }
        }
        onPositionChanged:{
            try {
                if (bubbleColor == 1){
                Qt.createQmlObject("import Qt 4.7\nImage {\n    id: whitebubble\n    x:" + mouseX + "-40  \n    y: " + mouseY + "-40 \n    source: 'images/Bluebubble.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 5000\n    }\n    Component.onCompleted: whitebubble.destroy(2000); \n} ", waterBubble, 'CustomObject');
                } else if (bubbleColor == 2)
                    {
                    Qt.createQmlObject("import Qt 4.7\nImage {\n    id: pinkbubble\n    x:" + mouseX + "-40  \n    y: " + mouseY + "-40 \n    source: 'images/bubble.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 5000\n    }\n    Component.onCompleted: pinkbubble.destroy(2000); \n} ", waterBubble, 'CustomObject');
                } else if (bubbleColor == 4)
                    {
                Qt.createQmlObject("import Qt 4.7\nImage {\n    id: bubble\n    x:" + mouseX + "-40  \n    y: " + mouseY + "-40 \n    source: 'images/Greenbubble.png'\n    NumberAnimation on opacity { \n        to: 0; duration: 5000\n    }\n    Component.onCompleted: bubble.destroy(2000); \n} ", waterBubble, 'CustomObject');
                }


            } catch(err) {
                dialog.show('Error on line ' + err.qmlErrors[0].lineNumber + '\n' + err.qmlErrors[0].message);
            }
        }
    }

    //This is the message box that pops up when there's an error    
    Rectangle {
        id: dialog

        opacity: 0
        anchors.centerIn: parent
        width: dialogText.width + 6; height: dialogText.height + 6
        border.color: 'black'
        color: 'lightsteelblue'
        z: 65535

        function show(str){
            dialogText.text = str;
            dialogAnim.start();
        }

        Text {
            id: dialogText
            x: 3; y: 3
            font.pixelSize: 14
        }

        SequentialAnimation {
            id: dialogAnim
            NumberAnimation { target: dialog; property:"opacity"; to: 1; duration: 1000 }
            PauseAnimation { duration: 5000 }
            NumberAnimation { target: dialog; property:"opacity"; to: 0; duration: 1000 }
        }
    }

    // water
    Rectangle {
        id: water
        width: parent.width
        height: parent.height
        radius: 0
        gradient: Gradient {
            GradientStop {
                position: 0
                color: "#0d4dcc"
            }

            GradientStop {
                position: 1.01
                color: "#3471f5"
            }

            GradientStop {
                position: 0.22
                color: "#446af5"
            }

            GradientStop {
                position: 0.99
                color: "#3b62ee"
            }

            GradientStop {
                position: 0.74
                color: "#0b53c0"
            }

            GradientStop {
                position: 0.22
                color: "#186dec"
            }

            GradientStop {
                position: 0.43
                color: "#2488f9"
            }

            GradientStop {
                position: 0.99
                color: "#0b4cb3"
            }
        }
    }

    // for bottom Tool
    Rectangle {
        id: toolBar
        width: parent.width; height: 32
        color: activePalette.window
        anchors.bottom: waterBubble.bottom

        Button {
            id: whiteBubble
            anchors { left: parent.left; leftMargin: 3; verticalCenter: parent.verticalCenter }
            text: "White"
            onClicked:  waterBubble.bubbleColor = 1
        }

        Button {
            id: pinkBubble
            anchors { left: whiteBubble.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
            text: "Pink"
            onClicked:  waterBubble.bubbleColor = 2
        }

        Button {
            id: greenBubble
            anchors { left: pinkBubble.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
            text: "Green"
            onClicked:  waterBubble.bubbleColor = 4
        }


        Button {
            id: about
            anchors { left: greenBubble.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
            text: "About Us"
            onClicked:  dialog.show('WaterBubble By: \nChintan Dave \n<chintannapster@live.in>');
        }


        Button {
            text: "Quit"
            anchors { left: about.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
            onClicked: Qt.quit();
        }
    }

    // small bubbles
    Particles {
        id: stars
        x: 0; y: 0; width: parent.width; height: parent.height - 32
        source: "images/SmallBluebubble.png"
        angleDeviation: 360
        velocity: 0; velocityDeviation: 0
        count: parent.width / 30
        fadeInDuration: 2000
        opacity: 3
    }

    SystemPalette { id: activePalette }



}
